package main

import (
	"fmt"
)

func main() {
	//定义字符串 工具包是strings 转化包strconv
	s := "hello"

	//通过索引获取字节
	fmt.Printf("ascii%d char:%c\n", s[1], s[1]) //ascii101 char:e

	//遍历字符串
	for i, c := range s {
		/*
			index:0 char:h
			index:1 char:e
			index:2 char:l
			index:3 char:l
			index:4 char:o
		*/
		fmt.Printf("index:%d char:%c\n", i, c)
	}

	//字符集合转字符串
	arr := []byte{65, 66, 67, 68}
	s1 := string(arr)
	fmt.Println(s1) //ABCD

	//字符串无法修改
	//s1[0] = 'G' //cannot assign to s1[0] (strings are immutable)
}
